package com.ququ.syb.mqhandler.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ququ.common.exception.QuQuException;
import com.ququ.common.result.Result;
import com.ququ.syb.common.constant.ResultStatusConstant;
import com.ququ.syb.common.pojo.AccountBalanceFlow;
import com.ququ.syb.mqhandler.fegin.AccountBalanceFlowFegin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountFlowService {
    @Autowired
    private AccountBalanceFlowFegin accountBalanceFlowFegin;

    public void saveAccountFlow(String message){
        JSONObject flowMap = JSON.parseObject(message);
        Result<AccountBalanceFlow> accountBalanceFlowResult =accountBalanceFlowFegin.saveAccountBalanceFlow(
                flowMap.getString("accountid"),
                flowMap.getString("tradenum"),
                flowMap.getLong("currentbalance"),
                flowMap.getLong("amount"),
                flowMap.getLong("afterbalance"),
                flowMap.getInteger("flowtype"),
                flowMap.getString("remark"),
                flowMap.getString("appcode"),
                flowMap.getString("channelid"),
                flowMap.getInteger("ordertype"));
        if (accountBalanceFlowResult.getStatus() != ResultStatusConstant.SUCCESS)
            throw new QuQuException(-1,"账户流水写入错误:"+message);
    }
}
